<template>
  <el-dialog ref="treeDiaRef" class="rounded-[15px]" width="40%" title="分类操作" :close-on-click-modal="false" v-model="show">
    <el-form :model="dialogProps.row">
      <el-form-item label="分类名称">
        <el-input placeholder="输入分类名" v-model="dialogProps.row.name"></el-input>
      </el-form-item>
    </el-form>
    <template #footer>
      <el-button type="primary" @click="confirm">确认</el-button>
    </template>
  </el-dialog>
</template>

<script setup lang="ts">
import { ref } from "vue";
import { ElMessage } from "element-plus";

interface DialogProps {
  row: { name: string; pid: number };
  api?: (params: any) => Promise<any>;
  refresh?: (params: any) => Promise<any>;
}

const dialogProps = ref<DialogProps>({ row: { name: "", pid: 1 } });

const treeDiaRef = ref();

const show = ref(false);

const acceptParams = (params: DialogProps) => {
  dialogProps.value = params;
  show.value = true;
};

const confirm = async () => {
  try {
    await dialogProps.value.api!(dialogProps.value.row);
    ElMessage.success("成功");
    await dialogProps.value.refresh!({ pid: 1 });
    show.value = false;
  } catch (error) {}
};

defineExpose({ acceptParams });
</script>

<style></style>
